package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_EXIT, desc = "玩家离线 和离开榷署座位")
public class MonopolyMarketExitSeatCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg.parseFrom(packet.getBytes());
        NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
        if(req.getIsExitMonopolyMarket()){
            marketModule.changeInSystemId(-1);
        }
        if(req.getIsExitOffice() || req.getIsExitResGrabKing() || req.getIsExitResGrabQueen()){
            marketModule.changeInSystemId(0);
        }
        NewMonopolyMarketMgr.exit(player,req.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
    }

}
